<?php
//搜索结果
$userid = intval($TS_USER['user']['userid']);

/*
$strKey = $db->once_fetch_assoc("select * from ".dbprefix."search_key where userid='$userid'");
if($strKey){
	$nowTime = time();
	$addtime = $strKey['addtime'];
	$forTime = $nowTime - $addtime;
	if($forTime < 30000) qiMsg("请等待30秒后再搜索！",'点击返回','index.php?app=search');
}
*/

$kw=urldecode(t($_GET['kw']));

$db->query("insert into ".dbprefix."search_key (`userid`,`keyword`,`addtime`) values ('$userid','$kw','".time()."')");

if($kw=='') qiMsg("关键词不能为空！");
if(strlen($kw)<2) qiMsg("不支持单字符查询，请至少写2个汉字");

switch($ts){
	case "":
		$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
		$url = "index.php?app=search&ac=s&kw=".$kw."&page=";
		$lstart = $page*10-10;
		
		$arrAlls = $db->fetch_all_assoc("select groupid as id,'group' as type from ".dbprefix."group where groupname like '%$kw%' or groupdesc like '%$kw%'  union select topicid as id,'topic' as type from ".dbprefix."group_topics WHERE title like '%$kw%' union select userid as id,'user' as type from ".dbprefix."user_info where username like '%$kw%' limit $lstart,10");
		
		foreach($arrAlls as $item){
			if($item['type']=='group'){
				$arrGroup[] = aac('group')->getOneGroup($item['id']);
			}elseif($item['type']=='topic'){
				$arrTopics[] = aac('group')->getOneTopic($item['id']);
			}elseif($item['type']=='user'){
				$arrUser[] = aac('user')->getUserForApp($item['id']);
			}
		}
	
		foreach($arrTopics as $key=>$titem){
			$arrTopic[] = $titem;
			$arrTopic[$key]['user'] = aac('user')->getUserForApp($titem['userid']);
		}
		$arrTTopicsall = $arrTopics;
		include 'letutao/showlist.php';
		$userid = intval($TS_USER['user']['userid']);
		
		$all_num = $db->once_num_rows("select groupid as id,'group' as type from ".dbprefix."group where groupname like '%$kw%' or groupdesc like '%$kw%'  union select topicid as id,'topic' as type from ".dbprefix."group_topics WHERE title like '%$kw%'");
		
		$pageUrl = pagination($all_num, 10, $page, $url);
		
		$title = $kw.' - 搜索分享的宝贝';
		
		include template("s_all");
		break;
}